<!--
 * @Author: Leo
 * @Date: 2021-12-08 11:40:44
 * @LastEditors: Leo
 * @LastEditTime: 2021-12-09 18:16:01
 * @Description: file content
-->
<template>
  <div
    id="app"
    class="pop-container"
  >
    <div
      v-if="$route.name !== 'login'"
      class="pop-header"
    >
      <span>亚马逊报表自动化下载管理器</span>
      <span>用户：{{ user.phone }}</span>
    </div>
    <router-view class="page-view" />

    <div
      v-if="$route.name !== 'login'"
      class="footer-main"
    >
      <el-tabs
        tab-position="bottom"
        @tab-click="toggleTab"
      >
        <el-tab-pane label="任务列表" />
        <el-tab-pane label="生成任务" />
      </el-tabs>
    </div>
  </div>
</template>

<script>
import bus from './bus'

export default {
  data() {
    return {
      user: {}
    }
  },
  mounted() {
    this.cachInit()
  },
  methods: {
    toggleTab(tab) {
      if(tab.label === '任务列表') {
        this.$router.push('/taskList')
        return
      }
      if(tab.label === '生成任务') {
        this.$router.push('/addTask')
      }
    },
    getBusData() {
      bus.$on('userData', (e) => {
        this.user = e || {}
      })
    },
    cachInit() {
      const that = this
      chrome.storage.local.get(['userData'], v => {
        if(v && v.userData) {
          that.user = v.userData
          return
        }
        that.getBusData()
      })
    }
  }
}
</script>

<style scoped>
@import url('../assets/css/normalize.css');
.pop-container {
  width: 350px;
  height: 450px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.page-view {
  flex: 1;
}

.pop-header {
  display: flex;
  justify-content: space-between;
  padding: 10px;
  font-size: 13px;
  color: #000;
  font-weight: bold;
  margin-bottom: 10px;
}
.footer-main {
  border-top: solid 1px #eaeefb;
  /* margin-top: -20px; */
}
.footer-main /deep/ .el-tabs {
  height: 30px;
}
.footer-main /deep/ .el-tabs__header {
  margin-top: 0;
}
.footer-main /deep/ .el-tabs__nav-scroll {
  display: flex;
  justify-content: center;
}
</style>
